<!-- Modal -->
<div class="modal-dialog wide" style="width: 1000px;">
<div class="modal-content">
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title" id="myModalLabel">
    <#if xmCgmj??>
        <#if xmCgmj.id??>
            编辑
        <#else>
            新增
        </#if>
    </#if>
    </h4>
</div>
<div class="modal-body">
<div id="errorMessage"><#include "../../message.ftl" /></div>
<form class="form-horizontal" role="form" id="xmCgmjForm" method="post"
      action="${absoluteContextPath}/xm/xmCgmj/save">
<#if xmCgmj??>
    <#if xmCgmj.id??>
    <input type="hidden" name="id" value="${xmCgmj.id?c}"/>
    <#else>
    <input type="hidden" name="id" value=""/>
    </#if>
</#if>
<div class="row">

    <div class="form-group col-md-6">
        <label class="col-sm-4 control-label">姓名</label>

        <div class="col-sm-8">
            <input name="userName" value="${xmCgmj.userName!''}" type="text" class="form-control"/>
        </div>
    </div>

    <div class="form-group col-md-6">
        <label class="col-sm-4 control-label">日期</label>

        <div class="col-sm-8">
            <input name="billTime" value="${xmCgmj.billTime!''}" type="text" class="form-control"/>
            <input type="hidden" name="fieldK" value="${xmCgmj.fieldK!''}" type="text" class="form-control"/>
        </div>
    </div>
</div>

<div class="row">
<#--<div class="tile-header">
    <h1>
        <button type="button" class="btn btn-green" onclick="doAddxmCgmj();"><i
                class="fa fa-plus"></i><span class="margin-left-5">新增</span></button>
    </h1>
</div>-->
<#assign  rowCount= 0/>
<div class="tile-body nopadding">
<div class="table-responsive" id="tableContent">
<table class="table-datatable table-gray" id="tab">
<thead>
<tr>
    <th style="display:none;">ID</th>
    <th id="bt">大类</th>
    <th id="bt">项目</th>
    <th id="bt">主合作健管完成人数</th>
    <th id="bt">拓展收费健管完成人数</th>
    <th id="bt">销售金额</th>
    <th id="bt">健管提报营业额</th>
    <th id="bt">健管核算营业额</th>
</tr>
</thead>
<tbody>
<#if xmCgmjA??>
    <#list xmCgmjA as xmCgmjA>
        <#assign  rowCount=rowCount+1 />
    <tr  <#if xmCgmjA.id??>id="${xmCgmjA.id?c!''}" </#if> align="center">
        <td style="display:none;"><input name="ids" <#if xmCgmjA.id??> value="${xmCgmjA.id?c!''}" </#if>
                                         type="text" class="form-control"/></td>
        <td><input name="DTypes" value="${xmCgmjA.DType!''}" type="text"
                   class="form-control" readonly="true"/></td>
        <td><input name="XTypes" value="${xmCgmjA.XType!''}" type="text"
                   id='XTypesA${rowCount}' style="width:150px;" class="form-control" readonly="true"/></td>
        <td><input name="fieldAs" value="${xmCgmjA.fieldA!''}" type="text"
                   id='fieldAsA${rowCount}' onblur=funMoney('${rowCount}','A') class="form-control"/></td>
        <td><input name="fieldBs" value="${xmCgmjA.fieldB!''}" type="text"
                   id='fieldBsA${rowCount}' onblur=funMoney('${rowCount}','A') class="form-control"/></td>
        <td><input name="fieldEs" value="${xmCgmjA.fieldE!''}" type="text"
                   id='fieldEsA${rowCount}' onblur=funMoney('${rowCount}','A') class="form-control"/></td>
        <td><input name="fieldCs" value="${xmCgmjA.fieldC!''}" type="text"
                   id='fieldCsA${rowCount}'  onblur=funMoney('${rowCount}','A') class="form-control" /></td>
        <td><input name="fieldDs" value="${xmCgmjA.fieldD!''}" type="text"
                   id='fieldDsA${rowCount}' class="form-control"/></td>
    </tr>

    </#list>

</#if>



</tbody>


<tr>
    <th style="display:none;">ID</th>
    <th id="bt">大类</th>
    <th id="bt">项目</th>
    <th id="bt">主合作体测完成人数</th>
    <th id="bt">拓展体测完成人数</th>
    <th id="bt">销售金额</th>
    <th id="bt">体测提报营业额</th>
    <th id="bt">体测核算营业额</th>
    <th id="bt"></th>


</tr>
</thead>
<tbody>
<#if xmCgmjC??>
    <#list xmCgmjC as xmCgmjC>
        <#assign  rowCount=rowCount+1/>
    <tr id="${xmCgmjC.id?c!''}" align="center">
        <td style="display:none;"><input name="ids" value="${xmCgmjC.id?c!''}"
                                         type="text" class="form-control"/></td>
        <td><input name="DTypes" value="${xmCgmjC.DType!''}" type="text"
                   class="form-control" readonly="true"/></td>
        <td><input name="XTypes" value="${xmCgmjC.XType!''}" type="text"
                   id='XTypesB${rowCount}' style="width:150px;" class="form-control" readonly="true"/></td>
        <td><input name="fieldAs" value="${xmCgmjC.fieldA!''}" type="text"
                   id='fieldAsB${rowCount}' onblur=funMoney('${rowCount}','B') class="form-control"/></td>
        <td><input name="fieldBs" value="${xmCgmjC.fieldB!''}" type="text"
                   id='fieldBsB${rowCount}' onblur=funMoney('${rowCount}','B') class="form-control"/></td>
        <td><input name="fieldEs" value="${xmCgmjC.fieldE!''}" type="text"
                   id='fieldEsB${rowCount}' onblur=funMoney('${rowCount}','B') class="form-control"/></td>
        <td><input name="fieldCs" value="${xmCgmjC.fieldC!''}" type="text"
                   id='fieldCsB${rowCount}'  onblur=funMoney('${rowCount}','B') class="form-control"  /></td>
        <td><input name="fieldDs" value="${xmCgmjC.fieldD!''}" type="text"
                   id='fieldDsB${rowCount}' class="form-control"/></td>

    </tr>
    </#list>

</#if>

</tbody>


<tr>
    <th style="display:none;">ID</th>
    <th id="bt">大类</th>
    <th id="bt">项目</th>
    <th id="bt">促会人数</th>
    <th id="bt">销售金额</th>
    <th id="bt">会员提报营业额</th>


</tr>
</thead>
<tbody>
<#if xmCgmjD??>
    <#list xmCgmjD as xmCgmjD>
        <#assign  rowCount=rowCount+1/>
    <tr id="${xmCgmjD.id?c!''}" align="center">
        <td style="display:none;"><input name="ids" value="${xmCgmjD.id?c!''}"
                                         type="text" class="form-control"/></td>
        <td><input name="DTypes" value="${xmCgmjD.DType!''}" type="text"
                   class="form-control" readonly="true"/></td>
        <td><input name="XTypes" value="${xmCgmjD.XType!''}" type="text"
                   id='XTypesC${rowCount}' style="width:150px;" class="form-control" readonly="true"/></td>
        <td><input name="fieldAs" value="${xmCgmjD.fieldA!''}" type="text"
                   id='fieldAsC${rowCount}' onblur=funMoney('${rowCount}','C') class="form-control"/></td>
        <td><input name="fieldEs" value="${xmCgmjD.fieldE!''}" type="text"
                   id='fieldEsC${rowCount}' onblur=funMoney('${rowCount}','C') class="form-control"/></td>
        <td style="display:none;"><input name="fieldBs" value="${xmCgmjD.fieldB!''}" type="text"
                                         id='fieldBsC${rowCount}' onblur=funMoney('${rowCount}','C')
                                         class="form-control"/></td>
        <td><input name="fieldCs" value="${xmCgmjD.fieldC!''}" type="text"
                   id='fieldCsC${rowCount}' onblur=funMoney('${rowCount}','C') class="form-control" /></td>
        <td style="display:none;"><input name="fieldDs" value="${xmCgmjD.fieldD!''}" type="text"
                                         class="form-control" /></td>

    </tr>


    </#list>

</#if>

</tbody>
<tr>
    <th style="display:none;">ID</th>
    <th id="bt">大类</th>
    <th id="bt">项目</th>
    <th id="bt">体检人数</th>
    <th id="bt">健管开单人数</th>
</tr>
</thead>
<tbody>
<#if xmCgmjB??>
    <#list xmCgmjB as xmCgmjB>

    <tr id="${xmCgmjB.id?c!''}" align="center">
        <td style="display:none;"><input name="ids" value="${xmCgmjB.id?c!''}"
                                         type="text" class="form-control"/></td>
        <td><input name="DTypes" value="${xmCgmjB.DType!''}" type="text"
                   class="form-control" readonly="true"/></td>
        <td><input name="XTypes" value="${xmCgmjB.XType!''}" type="text"
                   style="width:150px;" class="form-control" readonly="true"/></td>
        <td><input name="fieldAs" value="${xmCgmjB.fieldA!''}" type="text"
                   class="form-control"/></td>
        <td><input name="fieldBs" value="${xmCgmjB.fieldB!''}" type="text"
                   class="form-control"/></td>
        <td style="display:none;"><input name="fieldCs" value="${xmCgmjB.fieldC!''}" type="text"
                                         class="form-control"/></td>
        <td style="display:none;"><input name="fieldDs" value="${xmCgmjB.fieldD!''}" type="text"
                                         class="form-control"/></td>
        <td style="display:none;"><input name="fieldEs" value="${xmCgmjB.fieldE!''}" type="text"
                                         class="form-control"/></td>
    </tr>
    </#list>

</#if>

<tr >
<td style="background-color:greenyellow"><input    value="销售金额小计" class="form-control" type="text" readonly="true"/></td>
<td ><input  id="xsjjhj" value="" type="text" class="form-control" onfocus="this.blur()"/></td>
<td style="background-color:greenyellow"><input  value="提报营业额小计" type="text" class="form-control" readonly="true"/></td>
<td ><input  id="tbyyehj"value="" type="text" class="form-control" onfocus="this.blur()"/></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>

</form>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
    <button type="button" class="btn btn-primary" onclick="save();">保存</button>

</div>
</div>
</div>
<script>
    function save() {
        $("#" + "xmCgmjForm").ajaxSubmit({
            success: function (data) {
                data = JSON.parse(data);
                if (data.returnCode == 1) {
                    $('#myModal').modal("hide");
                    $.showMessage({parentId: "showMessage", message: "信息保存成功！", type: "success"});
                    refreshTable();
                } else {
                    $.showMessage({parentId: "errorMessage", message: "<strong>错误信息</strong>：" + data.returnMsg, type: "error"});
                }
            }
        });
    }

    $(function () {
        $("input[name=billTime]").focus(function () {
            WdatePicker({dateFmt: 'yyyy-MM-dd'});

        })
        $("div[class='tooltip fade top in']").hide();
    });
    function funMoney(rowCount, dif) {
        var money = 0;
        var bl = 0;
        if ($("input[id='XTypes" + dif + rowCount + "']").val() != '高级体姿体态' && $("input[id='XTypes" + dif + rowCount + "']").val() != '高级分布式体适能' && $("input[id='XTypes" + dif + rowCount + "']").val() != '高级银发族体感体适能' && $("input[id='XTypes" + dif + rowCount + "']").val() != '高级成人体感体适能' && $("input[id='XTypes" + dif + rowCount + "']").val() != '团体健管' && $("input[id='XTypes" + dif + rowCount + "']").val() != '颈腰椎套餐' && $("input[id='XTypes" + dif + rowCount + "']").val() != '医护人员减重' && $("input[id='XTypes" + dif + rowCount + "']").val() != '减重管理'&&  $("input[id='XTypes" + dif + rowCount + "']").val() != '慢病管理'&& $("input[id='XTypes" + dif + rowCount + "']").val() != '糖耐量') {
            if ($("input[id='XTypes" + dif + rowCount + "']").val() == '初级健管') {
                money = 50;
                bl = 0.9;
            } else if ($("input[id='XTypes" + dif + rowCount + "']").val() == '中级健管') {
                money = 100;
                bl = 0.8;
            } else if ($("input[id='XTypes" + dif + rowCount + "']").val() == '高级健管') {
                money = 200;
                bl = 0.75;
            }
            else if ($("input[id='XTypes" + dif + rowCount + "']").val() == '初级体姿体态') {
                money = 100;
                bl = 0.9;
            }
            else if ($("input[id='XTypes" + dif + rowCount + "']").val() == '生活方式问卷') {
                money = 10;
                bl = 1;
            }
            else if ($("input[id='XTypes" + dif + rowCount + "']").val() == '初级分布式体适能' || $("input[id='XTypes" + dif + rowCount + "']").val() == '初级银发族体感体适能') {
                money = 400;
                bl = 0.75;
            }
            var fieldA = $("input[id='fieldAs" + dif + rowCount + "']").val() * bl * money;
            var fieldB = $("input[id='fieldBs" + dif + rowCount + "']").val() * money;
            var fieldE = (fieldA + fieldB).toFixed(2);
            var fieldC = ((fieldA + fieldB) * 0.65).toFixed(2);
            $("#xmCgmjForm input[id='fieldCs" + dif + rowCount + "']").val(fieldC);
            $("#xmCgmjForm input[id='fieldEs" + dif + rowCount + "']").val(fieldE);
        }
        else if ($("input[id='XTypes" + dif + rowCount + "']").val() == '高级体姿体态' || $("input[id='XTypes" + dif + rowCount + "']").val() == '高级分布式体适能' || $("input[id='XTypes" + dif + rowCount + "']").val() == '高级银发族体感体适能' || $("input[id='XTypes" + dif + rowCount + "']").val() == '高级成人体感体适能' || $("input[id='XTypes" + dif + rowCount + "']").val() == '团体健管') {
            var fieldE = $("input[id='fieldEs" + dif + rowCount + "']").val() * 0.65;
            var fieldC = (fieldE).toFixed(2);
            $("#xmCgmjForm input[id='fieldCs" + dif + rowCount + "']").val(fieldC);
        }
        else if ($("input[id='XTypes" + dif + rowCount + "']").val() == '颈腰椎套餐' || $("input[id='XTypes" + dif + rowCount + "']").val() == '医护人员减重' || $("input[id='XTypes" + dif + rowCount + "']").val() == '减重管理'|| $("input[id='XTypes" + dif + rowCount + "']").val() == '慢病管理'|| $("input[id='XTypes" + dif + rowCount + "']").val() == '糖耐量') {
            var fieldE = $("input[id='fieldEs" + dif + rowCount + "']").val() * 0.65;
            var fieldC = (fieldE).toFixed(2);
            $("#xmCgmjForm input[id='fieldCs" + dif + rowCount + "']").val(fieldC);

        }

        var a = 0;
        b = 0;
        for (var i = 1; i < 18; i++) {
            if (i <= 5) {
                var c= $("input[id='fieldCsA" + i + "']").val();
                var d=$("input[id='fieldEsA" + i + "']").val();
                if (c!= "") {
                    a = parseFloat(a) + parseFloat(c) ;
                }
                if (d!= "") {
                    b = parseFloat(b)+ parseFloat(d);
                }
            }
            else if (i > 5 && i <= 12) {
                var c= $("input[id='fieldCsB" + i + "']").val();
                var d=$("input[id='fieldEsB" + i + "']").val();
                if (c!= "") {
                    a = parseFloat(a) + parseFloat(c) ;
                }
                if (d!="") {
                    b = parseFloat(b)+ parseFloat(d);
                }
            }
            else if (i > 12 && i <= 19) {
                var c= $("input[id='fieldCsC" + i + "']").val();
                var d=$("input[id='fieldEsC" + i + "']").val();
                if (c!= "") {
                    a = parseFloat(a) + parseFloat(c) ;
                }
                if (d!= "") {
                    b = parseFloat(b)+ parseFloat(d);
                }
            }

        }
        $("#xmCgmjForm input[id='xsjjhj']").val((b).toFixed(2));
        $("#xmCgmjForm input[id='tbyyehj']").val((a).toFixed(2));
    }



</script>
<style>

    #bt {
        text-align: center;
        font-size: 13px;
    }

</style>